<template>
     <div class="classify">
      <el-page-header @back="goBack" content="修改职位">
      </el-page-header>
<div style="margin: 20px;"></div>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="序号" prop="pid">
    <el-input type="text" v-model="ruleForm.pid" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="公司名称" prop="pname">
    <el-input type="text" v-model="ruleForm.pname" autocomplete="off"></el-input>
  </el-form-item>
  <el-form-item label="招聘岗位" prop="ptype">
    <el-input v-model.number="ruleForm.ptype"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
</el-form>

    </div>

</template>
<script>
  export default {
    data() {
      return {
        ruleForm: {
          pid: '',
          pname: '',
         ptype: ''
        },
           rules: {
         pname: [
            { required: true, message: '请输入公司名称', trigger: 'blur' },
            { min: 3, max: 10, message: '长度在 5 到 10 个字符', trigger: 'blur' }
          ],
         ptype: [
            { required: true, message: '请输入招聘职位', trigger: 'blur' }
          ],  
        }
      };
    },
     created() {
      let jobs =sessionStorage.jobs
      if(jobs){
        this.ruleForm = JSON.parse(jobs)
      }else{
        this.$router.push({
          path:'/job'
        })
      }
    },
    methods: {
      goBack(){
        this.$router.back()
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let params ={...this.ruleForm}
            this.$http({
              url:'/admin/position/Update',
              // method:'post',
              params:{
                pId:params.pid,
                pName:params.pname,
                pType:params.ptype
              }
            }).then(res=>{
              this.$message({
                message: '修改成功',
                type: res == 1 ? 'success' : 'error'
              })
            })
          } 
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>
<style scoped>
.el-input{
  width: 300px;
}
</style>